package com.uenpay.im.entities;

import java.text.DecimalFormat;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

/**
 *
 * @author  
 * @date 2014/7/21
 * 
 */
public class SendFile implements Parcelable {

	public String fileName = "";
	public int is_selected = 0;
	public int is_file = 0;
	public String fileSize = "";
	public String filePath = "";
	public String fileAddDate = "";
	public String getFileSize(String size) {
		final DecimalFormat df = new DecimalFormat("#.##");
		if (TextUtils.isEmpty(size)) {
			return "";
		}
		try {
			double sizes = Double.valueOf(size);
			if (sizes > 1024 * 1024f) {
				fileSize = df.format(sizes / (1024 * 1024)) + " M";
			} else if (sizes > 1024f) {
				fileSize = df.format(sizes / 1024) + " Kb";
			} else {
				fileSize = df.format(sizes) + " Byte";
			}
			return fileSize;
		} catch (Exception e) {
			return "";
		}

	}

	public SendFile() {
		super();
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(fileName);
		dest.writeInt(is_selected);
		dest.writeInt(is_file);
		dest.writeString(fileSize);
		dest.writeString(filePath);
		dest.writeString(fileAddDate);
	}

	public static final Creator<SendFile> CREATOR = new Creator<SendFile>() {

		@Override
		public SendFile createFromParcel(Parcel source) {
			SendFile file = new SendFile();
			file.fileName = source.readString();
			file.is_selected = source.readInt();
			file.is_file = source.readInt();
			file.fileSize = source.readString();
			file.filePath = source.readString();
			file.fileAddDate = source.readString();
			return file;
		}

		@Override
		public SendFile[] newArray(int size) {
			return null;
		}
	};
}